﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using DataObjectsPhone;
using ee_wp_tourmaker.WebServices;

namespace ee_wp_tourmaker
{
    public partial class FlagCheckPointPage : PhoneApplicationPage
    {
        private CheckPoint content;

        public FlagCheckPointPage()
        {
            InitializeComponent();
        }

        private void getSource()
        {
            content = App.MainModel.SelectedCheckPoint;
            nameLabel.Text = content.Name;
            DesciptionLabel.Text = content.Description;            
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            content.Done = true;
            if (App.MainModel.SelectedChallenge.checkpointsList.All(q=> q.Done))
            {
                var saveService = new SaveChangesService();
                App.MainModel.Changes.Items.Add(new AzureService.SyncItem
                {
                    ItemType = AzureService.SyncItemType.AddPersonAward,
                    AwardRequest = new AzureService.AddPersonAward
                    {
                        ChallengeId = App.MainModel.SelectedChallenge.Id,
                        Date = DateTime.Now,
                        PersonId = App.ProfileData.Id
                    }
                });
                saveService.SaveChangesStart();
            }
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }
    }
}
